﻿Imports DTO
Imports System.Windows.Forms

Public Class HoaDonDAO
    Public Sub Them(ByVal hdDTO As HoaDonDTO)
        Try
            Dim db As New QuanLyNhaSachDataContext
            Dim hd As New HoaDon
            hd.MaHD = hdDTO.MaHD
            hd.TenKH = hdDTO.TenKH
            hd.NgayLap = hdDTO.NgayLap
            hd.TongTien = hdDTO.TongTien

            db.HoaDons.InsertOnSubmit(hd)
            db.SubmitChanges()
            hdDTO.MaHD = hd.MaHD
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Public Sub CapNhat(ByVal hdDTO As HoaDonDTO)
        Try
            Dim db As New QuanLyNhaSachDataContext
            Dim hd As New HoaDon

            hd = db.HoaDons.Single(Function(p) p.MaHD = hdDTO.MaHD)
            hd.TenKH = hdDTO.TenKH
            hd.NgayLap = hdDTO.NgayLap
            hd.TongTien = hdDTO.TongTien

            db.SubmitChanges()
        Catch ex As Exception
            'MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub
End Class
